//
//  MyJourneyDetailViewController.m
//  didihaha
//
//  Created by 赵忠鹏 on 2017/8/16.
//  Copyright © 2017年 zhaozhongpeng. All rights reserved.
//

#import "MyJourneyDetailViewController.h"
#import "MyJourneyDetailDriverView.h"

@interface MyJourneyDetailViewController ()<QMapViewDelegate>

@property (nonatomic, strong)MyJourneyDetailDriverView *mainView;

@end

@implementation MyJourneyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setTitle:@"行程结束"];
    [self setLeftBackButton];
   
    self.mapView.delegate = self;
    [self.mapView setZoomLevel:10.01];
    // 起始点坐标
    QPointAnnotation *begin = [[QPointAnnotation alloc] init];
    begin.coordinate = CLLocationCoordinate2DMake([[NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"BeginLatitude"]] floatValue],[[NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"BeginLongitude"]] floatValue]);
    
    
    QPointAnnotation *stop = [[QPointAnnotation alloc] init];
    stop.coordinate = CLLocationCoordinate2DMake([[NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"StopLatitude"]] floatValue],[[NSString stringWithFormat:@"%@",[self.dataDic objectForKey:@"StopLongitude"]] floatValue]);
    
    
    //向mapview添加annotation
    [self.mapView addAnnotation:begin];
    [self.mapView addAnnotation:stop];
    
    [self.view addSubview:self.mainView];
    
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(10);
        make.right.equalTo(self.view.mas_right).offset(-10);
        make.bottom.equalTo(self.view.mas_bottom).offset(-10);
        make.height.mas_equalTo(300);
    }];
    
    
    
}



#pragma mark - 懒加载
- (MyJourneyDetailDriverView *)mainView{
    if (_mainView == nil) {
        _mainView = [[MyJourneyDetailDriverView alloc] init];
    }
    return _mainView;
}

-(QAnnotationView *)mapView:(QMapView *)mapView
          viewForAnnotation:(id<QAnnotation>)annotation {
    static NSString *customReuseIndentifier = @"custReuseIdentifieer";
    
    if ([annotation isKindOfClass:[QPointAnnotation class]]) {
        if ([annotation isEqual:[mapView.annotations objectAtIndex:0]]) {// 初始位置
            //添加自定义annotation
            CustomAnnotationView *annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndentifier];
            if (annotationView == nil) {
                annotationView = [[CustomAnnotationView alloc]
                                  initWithAnnotation:annotation
                                  reuseIdentifier:customReuseIndentifier];
                 annotationView.userInteractionEnabled = NO;
                //自定义的annotation图标
                UIImage *image = [UIImage imageNamed:@"common_icon_map_start_point_zh-CN"];
                annotationView.image = image;
                
                return annotationView;
            }
            
        }else if ([annotation isEqual:[mapView.annotations objectAtIndex:1]]){ //
            //添加自定义annotation
            CustomAnnotationView *annotationView = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:customReuseIndentifier];
            if (annotationView == nil) {
                annotationView = [[CustomAnnotationView alloc]
                                  initWithAnnotation:annotation
                                  reuseIdentifier:customReuseIndentifier];
                annotationView.userInteractionEnabled = NO;
                //自定义的annotation图标
                UIImage *image = [UIImage imageNamed:@"common_icon_map_end_point_zh-CN"];
                annotationView.image = image;
                return annotationView;
            }
        }
    }
    return nil;
    
}



- (void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    
    self.mainView.dataDic = dataDic;
   
}


@end
